package com.cw.controller;


import com.cw.common.api.ResultObject;
import com.cw.dto.InpatientRegistrationCondition;
import com.cw.entity.BaseDict;
import com.cw.entity.PatientInfo;
import com.cw.request.EemptyPatientRequest;
import com.cw.service.IBaseDictService;
import com.cw.service.IPatientInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author smq
 * @since 2021-04-27
 */
@Api(tags = {"患者信息"})
@RestController
@RequestMapping("/patient-info")
public class PatientInfoController {


    private IPatientInfoService targetService;

    private IBaseDictService baseDictService;

    @Autowired
    private void setterAutowiredMethod(IBaseDictService baseDictService,
                                       IPatientInfoService targetService) {
        this.baseDictService = baseDictService;
        this.targetService = targetService;
    }


    @ApiOperation(value = "根据病人id获取病人详情(病人ID,病人名称)")
    @GetMapping("/getPatientInfo")
    public ResultObject getPatientInfo(@RequestParam String id, @RequestParam String name) {
        return ResultObject.successReturn(targetService.getPatientInfo(id));
    }

    @ApiOperation(value = "根据床位id获取病人详情(病床ID,病人名称)")
    @GetMapping("/getEemptyBedsDetails")
    public ResultObject getEemptyBedsDetails(@RequestParam String bedId, @RequestParam String name) {
        return ResultObject.successReturn(targetService.getPatientDetail(bedId));
    }


    @ApiOperation(value = "获取没有床位的患者信息")
    @PostMapping("/getEemptyPatientList")
    public ResultObject getEemptyPatientList(@RequestBody EemptyPatientRequest emptyPatientRequest) {
        return ResultObject.successReturn(targetService.getEemptyPatientList(emptyPatientRequest));
    }

    @ApiOperation("住院登记记录列表")
    @PostMapping("/inpatientRegistrationList")
    public ResultObject inpatientRegistrationList(@RequestBody InpatientRegistrationCondition condition) {
        return ResultObject.successReturn(targetService.inpatientRegistrationList(condition));
    }

    @ApiOperation("手工录入字典表")
    @GetMapping("/getPatientBaseDict")
    public ResultObject getPatientBaseDict() {
        List<BaseDict> typeOfVisit = baseDictService.getBaseDictByIdResultList("1");
        List<BaseDict> sex = baseDictService.getBaseDictByIdResultList("2");
        List<BaseDict> maritalStatus = baseDictService.getBaseDictByIdResultList("7797a203b4d74951b868a087a9906563");
        List<BaseDict> allergy = baseDictService.getBaseDictByIdResultList("e3e659a839f44f43ad56258357de3340");

        Map<String,Object> resultMap = new HashMap<>(14);
        resultMap.put("typeOfVisit",typeOfVisit);
        resultMap.put("sex", sex);
        resultMap.put("maritalStatus", maritalStatus);
        resultMap.put("allergy", allergy);
        return ResultObject.successReturn(resultMap);
    }

    @ApiOperation("新增")
    @PostMapping("/insertPatientInfo")
    public ResultObject insertPatientInfo(@RequestBody PatientInfo patientInfo) {
        return ResultObject.successReturn(targetService.insertPatientInfo(patientInfo));
    }

    @ApiOperation("编辑")
    @PutMapping("/updatePatientInfo")
    public ResultObject updatePatientInfo(@RequestBody PatientInfo patientInfo) {
        return ResultObject.successReturn(targetService.updatePatientInfo(patientInfo));
    }


    @ApiOperation("逻辑删除")
    @DeleteMapping("/updateDeleteFlagToZero")
    public ResultObject updateDeleteFlagToZero(@RequestParam String id) {
        return ResultObject.successReturn(targetService.updateDeleteFlagToZero(id));
    }


    @ApiOperation("查看详情")
    @GetMapping("/getPatientInfoById")
    public ResultObject getPatientInfoById(@RequestParam String id) {
        return ResultObject.successReturn(targetService.getById(id));
    }
    @ApiOperation(value = "查询患者基本详情")
    @GetMapping("/getPatientInfoByIdenno")
    public ResultObject getPatientInfoByIdenno(@RequestParam String idenno){
        return ResultObject.successReturn(targetService.selectPatientInfoByIdenno(idenno));
    }

}

